package com.xtedu.examproject.service;

import com.xtedu.examproject.dao.base.StudentDao;
import com.xtedu.examproject.dao.impl.StudentDaoImpl;
import com.xtedu.examproject.entity.Student;
import com.xtedu.examproject.entity.StudentQuery;
import com.xtedu.examproject.util.PageHelper;

import java.util.List;

public class StudentService {
    private StudentDao studentDao;

    public StudentService() {
        studentDao = new StudentDaoImpl();
    }

    public int insertStudent(Student student) throws Exception {
        return studentDao.insert(student);
    }

    public int deleteStudent(Student student) throws Exception {
        return studentDao.delete(student);
    }

    public int updateStudent(Student student) throws Exception {
        return studentDao.update(student);
    }

    public Student findStudentById(int id) throws Exception {
        return studentDao.findById(id);
    }

    public List<Student> findAllStudent() throws Exception {
        return studentDao.findAll();
    }

    public PageHelper showPageByOwnClazz(int userId, int pageIndex, int pageSize) throws Exception {
        return ((StudentDaoImpl) studentDao).showPageByOwnClazz(userId, pageIndex, pageSize);
    }

    public List<Student> findNonUserStu(int teacherId) throws Exception {
        return studentDao.findNonUserStu(teacherId);
    }

    public List<Student> findNonUserStu() throws Exception {
        return studentDao.findNonUserStu();
    }

    public List<Student> searchStudents(Student query) throws Exception {
        return studentDao.searchStudents(query);
    }
    public List<Student> searchStudents(String keyWord, int gender, String classID, String eduBackground) throws Exception {
        return studentDao.searchStudents(keyWord, gender, classID, eduBackground);
    }

    public PageHelper findClassesStudents(int pageIndex, int pageSize, int classId) throws Exception {
        return studentDao.findStudentsByClassIdByPage(pageIndex, pageSize, classId);
    }
}
